package com.wyait.manage;


import com.wyait.manage.service.UserService;
import com.wyait.manage.utils.SpringSecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;


/**
 * spring boot 容器加载完成后执行
 *
 * @author huangjian
 */
@Component
@Slf4j
public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (event.getApplicationContext().getParent() == null) {
            ApplicationContext ac = event.getApplicationContext();
            UserService authService = ac.getBean(UserService.class);
            SpringSecurityUtils.authService = authService;
        }
    }
}